package com.atelier.plugin.database.ui;

import java.util.regex.Pattern;

public class DataBaseValid {

    public static boolean isValidPort(String portStr) {
        try {
            int port = Integer.parseInt(portStr);
            return (port >= 1 && port <= 65535);
        } catch (NumberFormatException e) {
            return false;
        }
    }
    public static boolean isValidPort(Integer port) {
        try {
            return (port >= 1 && port <= 65535);
        } catch (NumberFormatException e) {
            return false;
        }
    }
    public static boolean isValidHost(String host) {
        // 使用正则表达式来验证主机名格式
        String hostRegex = "^(?!-)[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(?<!-)$";
        Pattern pattern = Pattern.compile(hostRegex);

        return pattern.matcher(host).matches();
    }
}
